/*
 * RotationObject.cpp
 *
 *  Created on: 04.10.2012
 *      Author: caffeine
 */

#include "RotationObject.h"

namespace irr{
namespace object{

RotationObject::RotationObject(){
	rotation.set(0,0,0);
	rotation_lock=irr::thread::createRecursiveMutex();
}

RotationObject::RotationObject(irr::core::vector3df r){
	rotation=r;
	rotation_lock=irr::thread::createRecursiveMutex();
}

RotationObject::RotationObject(irr::f32 X,irr::f32 Y,irr::f32 Z){
	rotation.set(X,Y,Z);
	rotation_lock=irr::thread::createRecursiveMutex();
}

RotationObject::~RotationObject(){
	rotation_lock->drop();
}

irr::core::vector3df RotationObject::getRotation(){
	rotation_lock->lock();
	irr::core::vector3df temp=rotation;
	rotation_lock->unlock();
	return temp;
}
irr::f32 RotationObject::getRotationX(){
	return rotation.X;
}
irr::f32 RotationObject::getRotationY(){
	return rotation.Y;
}
irr::f32 RotationObject::getRotationZ(){
	return rotation.Z;
}

void RotationObject::setRotation(irr::core::vector3df r){
	rotation_lock->lock();
	rotation=r;
	rotation_lock->unlock();
}

void RotationObject::setRotation(irr::f32 X,irr::f32 Y,irr::f32 Z){
	rotation_lock->lock();
	rotation.set(X,Y,Z);
	rotation_lock->unlock();
}

void RotationObject::setRotationX(irr::f32 X){
	setRotation(irr::core::vector3df(X,getRotationY(),getRotationZ()));
}
void RotationObject::setRotationY(irr::f32 Y){
	setRotation(irr::core::vector3df(getRotationX(),Y,getRotationZ()));
}
void RotationObject::setRotationZ(irr::f32 Z){
	setRotation(irr::core::vector3df(getRotationX(),getRotationY(),Z));
}

void RotationObject::rotateX(irr::f32 X){
	setRotationX(getRotationX()+X);
}
void RotationObject::rotateY(irr::f32 Y){
	setRotationX(getRotationY()+Y);
}
void RotationObject::rotateZ(irr::f32 Z){
	setRotationX(getRotationZ()+Z);
}

irr::core::stringc RotationObject::getSerializationNodeName(){
	return "object::rotation";
}

void RotationObject::getSerialized(irr::xml::IXmlNode*node){
	node->setAttVec3F("rotation",getRotation());
}

irr::xml::TagResult RotationObject::setSerialized(irr::xml::IXmlNode*node){
	setRotation(node->getAttVec3F("rotation"));
	return irr::xml::NEXT;
}

}//namespace object
}//namespace irr
